package com.oa.system;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */

public class ApplicationException extends Exception {

  private Exception chainedException;
  /**
   * The reason of the application exception.
   */
  private Object reason;

  public ApplicationException(String s) {
    super(s);
  }

  /**
   * Constructs an application exception with the specified message,
   * and chained exception.
   * @param   msg     the message
   * @param   chainedException the chained exception
   */
  public ApplicationException(String msg, Exception chainedException) {
    this(msg, null, chainedException);
  }

  /**
   * Constructs an application exception with the specified chained exception.
   * @param   chainedException the chained exception
   */
  public ApplicationException(Exception chainedException) {
    this(null, null, chainedException);
  }

  /**
   * Constructs an application exception with the specified message,
   * reason, and chained exception.
   * @param   msg     the message
   * @param   reason  the exception reason
   * @param   chainedException the chained exception
   */
  public ApplicationException(
      String msg, Object reason, Exception chainedException) {
    super(msg == null ? "" : msg);
    this.chainedException = chainedException;
    this.reason = reason;
  }

  /**
   * Prints this exception and its stack trace to System.err.
   * If the exception has a chained exception, the stack trace of
   * the chained exception is also printed.
   */
  public void printStackTrace() {
    super.printStackTrace();
    if (chainedException != null) {
      System.err.println("Chained Exception:");
      chainedException.printStackTrace();
    }
  }

}